// 加载核心模块
const http=require("http");
const fs=require("fs");

//创建服务器
const server=http.createServer(function(request,response){
    console.log("-----------------服务器被访问了--------------------");
    let path=request.url;
    console.log(path);
    switch(path){
        case "/":
            let buffer1=fs.readFileSync("./public/home.html");
            let temp1=buffer1.toString();
            console.log(temp1);
            response.end(temp1);
            break;
        case "/user":
            let buffer2=fs.readFileSync("./public/user.html");
            let temp2=buffer2.toString();
            response.end(temp2);
            break;
        case "/favicon.ico":
            let buffer3=fs.readFileSync("./public/imgs/a.png");
            response.end(buffer3);
            break;
        default:
            let buffer4=fs.readFileSync("./public/404.html");
            let temp4=buffer4.toString();
            response.end(temp4);

    }
});

//启动服务器
server.listen(3000);